<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="app"></div>
    <div id="app1"></div>
    <div id="app2"></div>
    <script src="../js/babel.min.js"></script>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/prop-types.js"></script>
    <script type="text/babel">
      class Person extends React.Component {
        // 设置校验规则
        static propTypes = {
          name: PropTypes.string.isRequired,
          age: PropTypes.number,
          spack: PropTypes.func,
        };
        // 设置默认值
        static defaultProps = {
          sex: "未知",
          date: Date(),
        };
        render() {
          console.log(this);
          // props 不可修改
          const { name, age, sex, date } = this.props;
          return (
            <ul>
              <li>姓名：{name}</li>
              <li>年龄：{age + 1}</li>
              <li>性别：{sex}</li>
              <li>日期：{date}</li>
            </ul>
          );
        }
      }

      function spack() {
        console.log("spack...");
      }
      ReactDOM.render(
        <Person name="hyy" age="18" sex="男" spack={spack} />,
        document.getElementById("app")
      );
      const p = { name: "张三", age: 18 };
      ReactDOM.render(<Person {...p} />, document.getElementById("app1"));
      ReactDOM.render(
        <Person name="18" age={18} />,
        document.getElementById("app2")
      );
    </script>
  </body>
</html>
